草庐IT

c++ - Clang、std::next、libstdc++ 和 constexpr-ness

全部标签

c++ - 为什么 std::copy 不向量化?

考虑这个通用代码:#include#include#include//std::copyintmain(){constintn=1024;floata1[n],a2[n];std::srand(std::time(0));for(inti=0;i当我在Ubuntu上使用g++/gcc4.8.1和-O3-march=native-mtune=native标志编译时,我得到对应的行无法对拷贝进行矢量化,因为:note:notvectorized:notenoughdata-refsinbasicblock.如果我用for(inti=0;i我也收到了相同的编译器消息。我有点不解。直觉上我会想

c++ - 用户定义的重载运算符 * 与 std::chrono::duration

我创建了一个Frequency类模板,旨在与std::chrono::duration结合使用.Frequency对象存储每单位持续时间的周期数(两者都使用其类型的模板参数)。这个想法是将频率乘以持续时间产生一个Rep类型的对象。这是类定义。除了相关成员,我已经省略了所有成员。#include#includeusingnamespacestd::chrono;template>classFrequency{public:explicitFrequency(Repcycles):_cycles{cycles}{}friendRepoperator*(constFrequency&f,co

c++ - 是否有对两位值的 std::bitset 的概括?

假设我是一名基因组科学家,试图存储极长的字符串,每个字符串代表两位信息(即每个元素是G、A、T或C)。因为字符串非常长,所以我需要能够以精确的2N位(或者更确切地说,N/4字节)存储长度为N的字符串。考虑到这种动机,我正在寻找std::bitset的概括(或boost::dynamic_bitset)适用于两位值而不是一位值。我要存储N这样的两位值,每个值可以是0、1、2或3。我需要在内存中尽可能紧密地打包数据,所以vector将不起作用(因为它浪费了4倍的内存)。实现我的目标的最佳方式是什么?一种选择是用定制的operator[]包装现有的位集模板。、迭代器等,但如果可能的话,我更愿

c++ - std::is_class 的实现

我想知道std::is_class(http://www.cplusplus.com/reference/type_traits/is_class/)是如何实际实现的。我查看了/usr/include/c++/4.8/tr1/type_traits但似乎唯一存在的是:///is_classtemplatestructis_class:publicintegral_constant{};__is_class的定义在任何地方都找不到(或者我只是看得不够深入)。无论如何,如果有人能指出我在哪里寻找这个(以及std命名空间中的其他is_***),我会很高兴 最佳答案

c++ - 对 'cv::viz::Viz3d::Viz3d(std::string&const)' 的 undefined reference

我已经使用qtcreator运行了我的opencv代码,当我尝试使用Viz库时得到了这个答案。代码:#include#include#include#include#include///Createawindowviz::Viz3dmyWindow("VizDemo");///StarteventloopmyWindow.spin();///Eventloopisoverwhenpressedq,Q,e,Eprintf("Firsteventloopisover\n");///Accesswindowviaitsnameviz::Viz3dsameWindow=viz::getWind

c++ - 将 OSX Clang 配置为对 include 语句区分大小写

我知道C++include语句中区分大小写是一个文件系统问题(相关问题here和here)。是否可以将Clang配置为要求区分大小写的匹配以防止跨平台构建问题? 最佳答案 Clang现在有这些警告标志:-Wnonportable-include-path-Wnonportable-system-include-path第一个用于引用包含,第二个用于尖括号包含。它们甚至可以映射到错误:-Werror=nonportable-include-path-Werror=nonportable-system-include-path据推测,默

c++ - std::transform 到任意容器

我想编写通用函数,它接收container1的值为[a1,..,an]并返回另一个container2的值为[转换(a1),..,转换(an)]。如果container2是std::vector,问题就微不足道了,std::transform完全符合我的要求。下面的函数可以处理任意的container2和container1templateToTypeconvert(constFromType&from){std::vectortmp;std::transform(from.begin(),from.end(),std::back_inserter(tmp),[](consttypen

clang 中的 C++ 结构内存开销?

clang中是否存在每个结构的内存开销?通常结构的大小只是其所有成员的总大小。但是在clang中似乎不是这样:#includeusingnamespacestd;structObj{intx;inty;};intmain(){inta=42;intb=43;Objobj={100,101};intc=44;cout我用clang++program.cpp编译,没有优化。版本:Ubuntuclangversion3.4-1ubuntu3(tags/RELEASE_34/final)(basedonLLVM3.4)Target:x86_64-pc-linux-gnuThreadmodel:

c++ - 是否有可能从 gcc 或 clang 获得 Lexer 输出?

是否可以让clang或gcc显示词法分析阶段的结果? 最佳答案 虽然解析器doespollthelexer如果没有适当的“词法分析阶段”,这并不意味着您不能在词法分析时转储token。这是通过命令完成的:clang-fsyntax-only-Xclang-dump-tokenscode.c 关于c++-是否有可能从gcc或clang获得Lexer输出?,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com/

c++ - clang/g++ 与私有(private)继承和使用声明的区别

考虑以下代码:#includestructParams{};templatestructBase{intdata()const{return42;}};templateclassD,classP>structMiddle:privateD//mustbe'public'forg++{};structFinal:publicMiddle{usingBase::data;};intmain(){Finalf;std::cout此代码编译成功并打印42clang并在gcc上给我编译时错误'intBase::data()const[withT=Params]'isinaccessible在这种